﻿open SmartRoute.Data
open System.Xml.Serialization
open System.Runtime.Serialization
open System.Runtime.Serialization.Formatters.Binary
open SmartRoute.Analytics;
open SmartRoute.IO;

let path = @"U:\dev\data\stops.csv"

let lines = System.IO.File.ReadAllLines(path)

let allExceptFirstLine = lines.[1..]

let rows = 
    allExceptFirstLine
    |> Array.map (fun x -> x.Split([|','|]))

let ehs = new School("Ellensburg High School", Location.WithoutAddress(46.9921,-120.5233), Seq.empty)

let mms = new School("Morgan Middle School", Location.WithoutAddress(46.99246,-120.54293), Seq.empty)

let mses = new School("Mt. Stuart Elementary School", Location.WithoutAddress(47.00787,-120.55997), Seq.empty)

let vves = new School("Valley View Elementary School", Location.WithoutAddress(46.99241,-120.52297), Seq.empty)

let les = new School("Lincoln Elementary School", Location.WithoutAddress(46.99065,-120.53875), Seq.empty)

let stopFromRow (a : string array) = 
    let loc = Location.WithoutAddress(System.Double.Parse(a.[0]),System.Double.Parse(a.[1]))
    let addAction ((school : School),index) = 
        let x = System.Int32.Parse(a.[index]) in if(x>0) then school.addToStop(loc,x)
    Array.zip [|mses;mms;les;ehs;vves|] [|2..6|]
    |> Array.iter addAction

let mutationRate = 0.2

let buses = 30u

let ridingTimeLimit = System.TimeSpan.FromHours(1.0);

let passengerLimit = 60u

let populationSize = 30u

let timeCost = 10.0

let distanceCost = 4.0

let busCost = 1000.0

let overloadCost = 800.0

let overtimeCost = 600.0

let depot = new Location(46.995,-120.523262,"1598 E 3rd Ave")

let parameters = new CostFunctionParameters(timeCost,distanceCost,passengerLimit,ridingTimeLimit,overtimeCost,overloadCost,busCost)

let ourProject = new BingProject("AhqjOSdmQlNyiAfMcr8HicreBdxgTnuVaiMGVFnP9x3l_12WQgLyV1pRrfIpECX5",parameters,populationSize,buses,mutationRate,busCost,depot);

let bf = new BinaryFormatter()
//
//let outputFile (sch : School) = bf.Serialize(System.IO.File.Create("U:\\dev\\data\\" + sch.SchoolName + ".smrtsch"),sch)
//
let main = 
    Array.iter stopFromRow rows
    Array.iter ourProject.addSchool [|ehs;mms;mses;vves;les|]
    bf.Serialize(System.IO.File.Create("current.smrtprj"),ourProject);
    
do main
